package cn.zy.jboa.action;


import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import cn.zy.jboa.entity.SysEmployee;
import cn.zy.jboa.service.SysEmployeeService;

import com.opensymphony.xwork2.ActionSupport;

public class SysEmployeeAction extends ActionSupport {
	@Autowired
	@Qualifier("sysEmployeeService")
	SysEmployeeService sysEmployeeService;
	
	SysEmployee employee;
	
	public SysEmployee getEmployee() {
		return employee;
	}

	public void setEmployee(SysEmployee sysEmployee) {
		this.employee = sysEmployee;
	}

	public void setSysEmployeeService(SysEmployeeService sysEmployeeService) {
		this.sysEmployeeService = sysEmployeeService;
	}
	
	public String login(){
		employee = sysEmployeeService.login(this.employee);
		if(this.employee!=null){
			String position = this.employee.getSysPosition().getNameCn();
			SysEmployee manager = sysEmployeeService.managerList(employee.getSysDepartment().getId().toString());
			ServletActionContext.getRequest().getSession().setAttribute("employee", this.employee);
			ServletActionContext.getRequest().getSession().setAttribute("employee_position", position);
			ServletActionContext.getRequest().getSession().setAttribute("manager", manager);
			return SUCCESS;
		}else{
			addFieldError("a","工号或密码错误");
			return ERROR;
		}
	}
}
